package com.ygo.feihua;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.view.View;


import cn.bmob.v3.listener.SaveListener;
import cn.bmob.v3.exception.BmobException;
import com.ygo.feihua.BmobTable.GongGao;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.ygo.feihua.util.*;

public class GonggaoAdd extends AppCompatActivity implements OnClickListener
{

	Button ggadd_back;
	Button ggadd_add;
	EditText ggadd_bt,ggadd_nr;
	Gongju gj;
	private DialogUtils du;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gonggao_add);
		csh();
		
		gj.cshToolbar((Toolbar) findViewById(R.id.toolbar),"返回");
		
	}
	private void csh(){
		ggadd_add=(Button) findViewById(R.id.ggadd_add);
		ggadd_bt=(EditText) findViewById(R.id.ggadd_bt);
		ggadd_nr=(EditText) findViewById(R.id.ggadd_nr);
		
		gj=Gongju.getdx(this);
		du=DialogUtils.getdx(this);
		ggadd_add.setOnClickListener(this);
	}

	@Override
	public void onClick(final View view)
	{
		switch(view.getId()){
			case R.id.ggadd_add:
			
				String bt,nr;
				bt=ggadd_bt.getText().toString().trim();
				nr=ggadd_nr.getText().toString().trim();
				if(bt.equals("")||nr.equals("")){
					gj.show("信息未填完整");
					}else{
						du.dialogj1(false,"","加载中,请稍等");
				GongGao gg=new GongGao();
				gg.setBiaoti(bt);
				gg.setNeirong(nr);
				gg.save(new SaveListener<String>(){

						@Override
						public void done(String p1, BmobException p2)
						{
							if(p2==null){
								du.dis();
								gj.show("添加成功");
								finish();
							}else{
								du.dis();
								gj.toastBmobException(view,"添加失败",p2);
							}
							// TODO: Implement this method
						}
					});
					}
				break;
		}
		
		// TODO: Implement this method
	}

	
}
